home *** CD-ROM | disk | FTP | other *** search
- #include <Packages.h>
-
- #include "FormatVal.h"
-
- /*
- -- Michael Hecht (Michael_Hecht@mac.sas.com)
- August 5, 1993
- */
-
-
- OSErr FormatVal( double x, short formatID, StringPtr formattedX )
- {
- NumberParts parts;
-
- NumFormatString **format;
- Handle itl4;
- long offset, length;
-
- FormatStatus status;
-
-
- /* Just in case! */
- Length( formattedX ) = 0;
-
- /* Get default Number Parts resource/offset/length */
- GetIntlResourceTable( iuCurrentScript, iuNumberPartsTable, &itl4, &offset, &length );
- if( !itl4 )
- return paramErr;
-
- /* Retrieve default Number Parts Table */
- parts = *( NumberPartsPtr )( *itl4 + offset );
-
- /* Retrieve canonical format */
- format = ( NumFormatString ** )GetResource( 'FMAT', formatID );
- if( !format )
- return resNotFound;
-
- /* Lock it */
- HLock(( Handle )format );
-
- /* Format it! */
- // This should work in THINK C 6.0, but it doesn't due to an H file error. Therefore,
- // we coerce x into an extended80.
- // status = ExtendedToString( x, *format, &parts, formattedX );
- status = ExtendedToString( *( extended80 * )&x, *format, &parts, formattedX );
-
- /* Unlock the canonical format */
- HUnlock(( Handle )format );
-
- return status;
- }
-